package com.ruoyi.web.controller.business;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbServiceStation;
import com.ruoyi.system.service.ITbServiceStationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商户相关controller
 * 
 * @author admin
 * @date 2022-05-06
 */
@Controller
@RequestMapping("/service/station")
public class ServiceStationController extends BaseController
{
    private static final Logger logger = LoggerFactory.getLogger(ServiceStationController.class);
    @Autowired
    private ITbServiceStationService tbServiceStationService;

    @RequiresPermissions("service:station:view")
    @GetMapping()
    public String station()
    {
        return "business/station/station";
    }

    /**
     * 查询站列表
     */
    @RequiresPermissions("service:station:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbServiceStation tbServiceStation)
    {
        startPage();
        List<TbServiceStation> list = tbServiceStationService.selectTbServiceStationList(tbServiceStation);
        return getDataTable(list);
    }

    /**
     * 导出站列表
     */
    @RequiresPermissions("service:station:export")
    @Log(title = "站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbServiceStation tbServiceStation)
    {
        List<TbServiceStation> list = tbServiceStationService.selectTbServiceStationList(tbServiceStation);
        ExcelUtil<TbServiceStation> util = new ExcelUtil<TbServiceStation>(TbServiceStation.class);
        return util.exportExcel(list, "站数据");
    }

    /**
     * 新增站
     */
    @GetMapping("/add")
    public String add()
    {
        return "business/station/add";
    }

    /**
     * 新增保存站
     */
    @RequiresPermissions("service:station:add")
    @Log(title = "站", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbServiceStation tbServiceStation)
    {
        return toAjax(tbServiceStationService.insertTbServiceStation(tbServiceStation));
    }

    /**
     * 修改站
     */
    @RequiresPermissions("service:station:edit")
    @GetMapping("/edit/{stationId}")
    public String edit(@PathVariable("stationId") Integer stationId, ModelMap mmap)
    {
        TbServiceStation tbServiceStation = tbServiceStationService.selectTbServiceStationByStationId(stationId);
        mmap.put("tbServiceStation", tbServiceStation);
        return "business/station/edit";
    }

    /**
     * 修改保存站
     */
    @RequiresPermissions("service:station:edit")
    @Log(title = "站", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbServiceStation tbServiceStation)
    {
        return toAjax(tbServiceStationService.updateTbServiceStation(tbServiceStation));
    }

    /**
     * 删除站
     */
    @RequiresPermissions("service:station:remove")
    @Log(title = "站", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbServiceStationService.deleteTbServiceStationByStationIds(ids));
    }
}
